package net.lzzy.spark;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.FlatMapFunction;
import org.apache.spark.api.java.function.Function;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class SparkFlatMap {
    public static String test;
    public static void main(String[] args) {
        SparkConf conf = new SparkConf().setAppName("SparkTextFile").setMaster(args[0]);
        JavaSparkContext javaSparkContext = new JavaSparkContext(conf);
        JavaRDD<String> javaRDD = javaSparkContext.textFile("D:\\Spark\\hello.txt");
        JavaRDD<String> newRDD = javaRDD.flatMap((FlatMapFunction<String, String>) item ->{
            return Arrays.asList(item.split(" ")).iterator();
        });
        List<String> collect = newRDD.collect();
        for (String s : collect) {
            System.out.println(s);
        }
    }
}
